package ru.exigenservices.intern.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Required;
import ru.exigenservices.intern.dao.ContactDao;
import ru.exigenservices.intern.dao.GroupDao;
import ru.exigenservices.intern.model.Contact;
import ru.exigenservices.intern.model.Group;
import ru.exigenservices.intern.service.AddressBookService;

import java.util.List;

public class AddressBookServiceImpl implements AddressBookService {
    public List<Contact> getContacts() {
        return contactDao.getAll();
    }

    public Contact getContact(Long id) {
        return contactDao.get(id);
    }

    public Contact saveContact(Contact contact) {
        return contactDao.save(contact);
    }

    public Contact deleteContact(Contact contact) {
        return contactDao.delete(contact.getId());
    }

    public List<Group> getGroups(){
        return groupDao.getAll();
    }
    
    public Group getGroup(Long id){
        return groupDao.get(id);
    }
    public Group saveGroup(Group group){
        return groupDao.save(group);
    }

    public Group deleteGroup(Group group) {
        return groupDao.delete(group.getId());
    }

    @Required
    public void setContactDao(ContactDao contactDao) {
        this.contactDao = contactDao;
    }
    
    @Required
    public void setGroupDao(GroupDao groupDao){
        this.groupDao = groupDao;
    }

    private ContactDao contactDao;
    private GroupDao groupDao;
}
